\defmodule {PascalGen}

Implements Pascal random variate generators, which is a special case of the
negative binomial generator with parameter $\gamma$ equal to a positive integer.
See \class{NegativeBinomialGen} for a description.


\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        PascalGen
 * Description:  Pascal random variate generators
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class PascalGen extends RandomVariateGenInt \begin{hide} {
   protected int    n;
   protected double p;    
\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public PascalGen (RandomStream s, int n, double p)\begin{hide} {
      super (s, new PascalDist (n, p));
      setParams (n, p);
   }\end{hide}
\end{code}
  \begin{tabb}
  Creates a Pascal random variate generator with parameters $n$ and $p$,
  using stream \texttt{s}.
 \end{tabb}
\begin{code}

   public PascalGen (RandomStream s, PascalDist dist)\begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getN1(), dist.getP());
   }\end{hide}
\end{code}
  \begin{tabb}
  Creates a new generator for the distribution \texttt{dist}, using
  stream \texttt{s}.
 \end{tabb}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}
    
   public static int nextInt (RandomStream s, int n, double p)\begin{hide} {
      return PascalDist.inverseF (n, p, s.nextDouble());
   }\end{hide}
\end{code}
\begin{tabb}
 Generates a new variate from the \emph{Pascal} distribution,
 with parameters $n = $~\texttt{n} and $p = $~\texttt{p}, using stream \texttt{s}.
 \end{tabb}
\begin{code}

   public int getN()\begin{hide} {
      return n;
   }
   \end{hide}
\end{code}
\begin{tabb} Returns the parameter $n$ of this object.
\end{tabb}
\begin{code}

   public double getP()\begin{hide} {
      return p;
   }
   \end{hide}
\end{code}
\begin{tabb} Returns the parameter $p$ of this object.
\end{tabb}
\begin{hide}\begin{code}

   protected void setParams (int n, double p) {
      if (p < 0.0 || p > 1.0)
         throw new IllegalArgumentException ("p not in [0, 1]");
      if (n <= 0)
         throw new IllegalArgumentException ("n <= 0");
      this.p = p;
      this.n = n;
   }
\end{code}
\begin{tabb} Sets the parameter $n$ and $p$ of this object.
\end{tabb}
\begin{code}
}\end{code}
\end{hide}
